package com.fr.lintcode;

import org.junit.Test;

public class Q75ii {
	/**
	 * @param A: An integers array.
	 * @return: return any of peek positions.
	 */
	public int findPeak(int[] A) {
		if (A == null || A.length < 2) {
			return -1;
		}
//		int i = 1;
//		boolean leftCompare = false;
//		while (i < A.length - 1) {
//			int c = A[i] - A[i + 1];
//			if (c > 0) {
//				if (leftCompare || A[i] > A[i - 1]) {
//					return i;
//				} else {
//					i = i + 2;
//					leftCompare = false;
//				}
//			} else if(c == 0){
//				i = i + 2;
//				leftCompare = false;
//			}else {
//				i = i + 1;
//				leftCompare = true;
//			}
//		}
		int left = 0, right = A.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (A[mid] < A[mid + 1]) left = mid + 1;
            else right = mid;
        }
        return right;
	}

	@Test
	public void testA() {
		int[] a = { 1, 1,1};
		System.out.println(findPeak(a));
	}
}
